home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Info-Mac 4
/
Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso
/
Applications
/
Tax ƒ
/
Tax.p
< prev
Wrap
Text File
|
1994-05-07
|
3KB
|
95 lines
{ Tax.p }
{ Source file for Tax FKEY }
{ Since this was written in THINK Pascal, some portions might be }
{ copyrighted to Symantec Corporation. }
{ Copyright © 1993, 1994 by David Alten. All rights reserved. }
{ version 1.0.1 }
unit myFKEY;
interface
procedure main; { all code resources must have a MAIN procedure }
implementation
procedure main;
const
tax = 1.0825; { the tax rate in TX is 8.25% }
label
0;
type
IndexType = 1..12; { If you make more than this many digits, you can probably hire }
{ an accountant to do the work for you!!! }
{ PACs are better than STRINGS, especially if they are 4 bytes long }
PACType = packed array[indextype] of char;
PACPtrType = ^PACType;
var
aHandle: handle; { Handle to Text from Scrap }
thePACPtr: PACPtrType; { Same as PACPtr in argument, }
{ use PACPtr to avoid static link }
{ overhead }
Offset, theScrapLength, num: longint;
thenum: str255;
{ convert a character digit to a number }
function number (ch: char): integer;
begin
number := -1;
if (ch >= '0') and (ch <= '9') then
number := ord(ch) - 48;
end;
begin
aHandle := NewHandle(0);
theScrapLength := GetScrap(aHandle, 'TEXT', Offset);
if (theScrapLength <= 0) or (aHandle = nil) or (theScrapLength > 10) then
goto 0; { quit }
HLock(aHandle);
thePACPtr := PACPtrType(aHandle^);
num := 0;
for Offset := 1 to theScrapLength do
if number(thePACPtr^[Offset]) >= 0 then { ignore characters in between }
num := num * 10 + number(thePACPtr^[Offset]);
{ check to see if you only one digit after the decimal point; adjust if you do }
if (thePACPtr^[theScrapLength - 1] = '.') then
num := num * 10;
{ compute the new number and convert it to a string }
numtostring(round(num * tax), thenum);
{ you will get two decimal places }
insert('.', thenum, length(thenum) - 1);
{ if your result is less than 10 cents, you get something like ".4" instead of ".04" }
if length(thenum) = 2 then
insert('0', thenum, length(thenum));
offset := ZeroScrap; { clear the clipboard }
{ copy the stuff back in the clipboard }
if Offset = noerr then
Offset := PutScrap(length(thenum), 'TEXT', @thenum[1]); { thenum[0] contains the length }
0:
HUnlock(aHandle);
if aHandle <> nil then { ALWAYS check to see if a Handle }
{ is NIL before disposing it }
DisposHandle(aHandle);
end;
end. { THE END!! }
{ HE KUER!! }